#include "common/ota/ota.h"

ESP8266WebServer server(80);
ESP8266HTTPUpdateServer httpUpdater;

String WEB_OTA_createWebServer()
{
    /* You can remove the password parameter if you want the AP to be open. */
    WiFi.softAP(aPSsid, aPPassword);

    IPAddress myIP = WiFi.softAPIP();
    server.on("/", handle_OnConnect);
    server.onNotFound(handle_NotFound);

    // 网页更新固件
    httpUpdater.setup(&server);

    server.begin();
    return myIP.toString();
}

void handle_OnConnect()
{
    //server.send(200, "text/plain", "Success!");
    String html = readFile("/index.html");
    html.replace("{ssid}", ssid);
    html.replace("{password}", password);
    server.send(200, "text/html", html);
}

void handle_NotFound()
{
    server.send(404, "text/plain", "Not found");
}

void handle_Client()
{
    if (1 == needOTA)
    {
        // 检查http服务器访问
        server.handleClient();
        return;
    }
}